package cn.initcap.designpattern.pattern.behavioral.memento;

/**
 * 备忘录模式
 *
 * @author initcap
 * @date Created in 2018/10/14 PM8:52.
 */
public class Test {

    public static void main(String[] args) {
        ArticleMementoManager articleMementoManager = new ArticleMementoManager();

        Article article = new Article("A计划", "这是内容", "图片");

        ArticleMemento articleMemento = article.saveToMemento();

        articleMementoManager.addMemento(articleMemento);
        System.out.println("标题:" + article.getTitle() + "内容:" + article.getContent() + "图片:" + article.getImgs());

        System.out.println("手记完整信息:" + article);

        System.out.println("修改手记start");

        article.setTitle("B计划");
        article.setContent("修改1");
        article.setImgs("图片B");

        System.out.println("修改手记end");

        System.out.println("手记完整信息:" + article);

        articleMemento = article.saveToMemento();
        articleMementoManager.addMemento(articleMemento);

        System.out.println("暂存回退start");

        System.out.println("回退出栈1次");
        articleMemento = articleMementoManager.getMemento();
        article.undoFromMemento(articleMemento);

        System.out.println("回退出栈2次");
        articleMemento = articleMementoManager.getMemento();
        article.undoFromMemento(articleMemento);

        System.out.println("暂存回退end");
        System.out.println("手记完整信息:" + article);
    }
}
